package com.smart.springaiopen.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author Guoxinyu
 * @description: TODO
 * @date 2025/5/28 10:44
 * @email gxy06x@qq.com
 */
@RestController
public class ChatClientControllerAuto {
    private static final Logger log = LoggerFactory.getLogger(ChatClientControllerAuto.class);
    @Autowired
    private ChatClient chatClient;

    @GetMapping("/auto/chat")
    public String chat(@RequestParam(value = "msg", defaultValue = "hello")  String msg) {
        String content = chatClient.prompt() //提示词
                .user(msg)//用户输入信息
                .call() //调用
                .content();//获取结果
        log.info("content:{}", content);
        return content;
    }
    @GetMapping(value = "/stream/chat",produces = "text/html;charset=UTF-8")
    public Flux<String> chatStream(@RequestParam(value = "msg", defaultValue = "hello")  String msg) {
        Flux<String> content = chatClient.prompt() //提示词
                .user(msg)//用户输入信息
                .stream() //流式输出
                .content();
        return content;
    }
}
